package com.hxzy.remote.fallback;

import com.hxzy.common.enums.AckCode;
import com.hxzy.common.vo.R;
import com.hxzy.product.entity.Sku;
import com.hxzy.remote.ProductServiceOpenFeignApi;
import feign.hystrix.FallbackFactory;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 功能描述
 *
 * @author tonneyyy
 */
@Component
@Log4j2
public class ProductServiceOpenFeignApiFallBackFactory implements FallbackFactory<ProductServiceOpenFeignApi> {
    @Override
    public ProductServiceOpenFeignApi create(Throwable throwable) {
        //记录日志
        log.error(throwable);
        //hystrix服务断熔实现
        return new ProductServiceOpenFeignApi() {


            @Override
            public R<List<Sku>> findSkusBySpuId(String spuId) {
                return R.build(AckCode.COMMON_FRE_OPERATION);
            }

            @Override
            public R findSpuById(String id) {
                return R.build(AckCode.COMMON_FRE_OPERATION);
            }

            @Override
            public R findNameByCategoryIds(Integer[] ids) {
                return R.build(AckCode.COMMON_FRE_OPERATION);
            }
        };
    }
}
